package com.wjc.train.common.untils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wjc.train.common.entity.QueryPage;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * @author Guessed
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageUtil {
    /**
     * 总记录数
     */
    private int totalCount;
    /**
     * 每页记录数
     */
    private int pageSize;
    /**
     * 总页数
     */
    private int totalPage;
    /**
     * 当前页
     */
    private int currPage;
    /**
     * 列数据
     */
    private List<?> list;

    public PageUtil(IPage<?> page) {
        this.list = page.getRecords();
        this.totalCount = (int)page.getTotal();
        this.pageSize = (int)page.getSize();
        this.currPage = (int)page.getCurrent();
        this.totalPage = (int)page.getPages();
    }

    public static <T> IPage<T> getPage(QueryPage queryPage) {
        return new Page<>(queryPage.getCurrent() == null ? 1:queryPage.getCurrent(), queryPage.getSize() == null ? 10:queryPage.getSize());
    }
}
